﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Manager.App_Code;
using System.Linq;
using Manager.ViewModels;
using Manager.Common;

namespace Manager.FormAdd_Edit
{
    public partial class frm_ListRoomRegistered : DevExpress.XtraEditors.XtraForm
    {
        NewPearl_HotelDataContext db = new NewPearl_HotelDataContext();
        public string _MaPhieuDangKy = "";
        public string _MaPhong = "";
        public string _TenKhachHang = "";

        public frm_ListRoomRegistered()
        {
            InitializeComponent();
        }

        private void frm_ListRoomRegistered_Load(object sender, EventArgs e)
        {
            var lstPhieuDangKy = db.PhieuDangKyPhongs.Where(i => i.TinhTrang == false).ToList();
            if (lstPhieuDangKy != null)
            {
                var lstPhongCoKhach = new List<PhongCoKhachViewModel>();
                foreach (var phieuDangKy in lstPhieuDangKy)
                {
                    var viewmodel = new PhongCoKhachViewModel();
                    var phong = db.Phongs.SingleOrDefault(i => i.MaPhong == phieuDangKy.ChiTietPhieuDangKy.MaPhong);
                    viewmodel.MaPhieuDangKy = phieuDangKy.MaPhieu;
                    viewmodel.TenKhachHang = phieuDangKy.ChiTietPhieuDangKy.KhachHang.TenKH;
                    viewmodel.MaPhong = phong.MaPhong;
                    viewmodel.TenPhong = phong.TenPhong;
                    viewmodel.MaLoaiPhong = phong.LoaiPhong1.MaLoaiPhong;
                    viewmodel.TenLoaiPhong = phong.LoaiPhong1.TenLoaiPhong;
                    viewmodel.Gia = phong.LoaiPhong1.GiaPhong == null ? 0 : phong.LoaiPhong1.GiaPhong.Value;
                    viewmodel.strGia = CommonFunction.AddSeparator(viewmodel.Gia);
                    lstPhongCoKhach.Add(viewmodel);
                }
                gridControl1.DataSource = lstPhongCoKhach;
            }
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            int index = gridView1.FocusedRowHandle;
            var vm = gridView1.GetRow(index) as PhongCoKhachViewModel;
            _MaPhieuDangKy = vm.MaPhieuDangKy.ToString();
            _MaPhong = vm.MaPhong;
            _TenKhachHang = vm.TenKhachHang;
            this.Close();
        }
    }
}